#include <matrix.hpp>

#include <random.hpp>

#include <algorithm>
#include <iostream>
#include <cstddef>
#include <ctime>

#include <boost/lambda/lambda.hpp>


using namespace sm;

int main()
{
#if 0
	const std::size_t n = 100;

	feng::variate_generator<double> vg( -1.0, 1.0 );

	for ( std::size_t i = 1; i < n; ++i )
	{
		dynamic_matrix<double> m( i, i );
		std::copy( vg.begin(), vg.begin()+i*i, m.begin() );

		dynamic_matrix<int> u = m * m.invert() + 0.1;
		std::cout 	<< i << "th test: \n"
					<< u << "\n" << std::endl;
	}
#endif

#if 0
	const int N = 5;

	dynamic_matrix<int> m( N, N );

	int i = 0;
	std::for_each( m.begin(), m.end(), boost::lambda::_1 = boost::lambda::var(i)++ );

	dynamic_matrix<int> e( N, N );
	std::for_each( e.diag_begin(), e.diag_end(), boost::lambda::_1 = 1 );

	std::cout 	<< "\nm and e are: \n "
				<< m << "\n"
				<< e;

	std::cout 	<< "\n m * e is :\n" 
				<< m * e;
	
	std::cout 	<< "\n e * m is :\n" 
				<< e * m;
#endif

	//const std::size_t dim = 2003;
	const std::size_t dim = 1009;
	//const std::size_t dim = 503;

	dynamic_matrix<double> d( dim, dim );

	double ul = 1;
	std::for_each( d.begin(), d.end(), boost::lambda::_1 = boost::lambda::var(ul)++ );

	clock_t start = clock();
	d *= d;
	clock_t finish = clock();


	//threshold = 12 <- duration = 6780000
	std::cout << "\n duaration is " << finish-start << "\n";


	//const double sum = std::accumulate( d.diag_begin(), d.diag_end(), 0.0f );
	std::cout << "\nthe first value is  \n" << d[0][0];

	return 0;
}
